package com.my.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.query.Query;

import com.my.object.Apartment;

public class ApartmentDao {
	private static Session session;
	static {
		session = HibernateDao.getSession();
	}

	public static List<Apartment> search() {
		Query<Apartment> query = session.createQuery(
				"from Apartment", Apartment.class);
		return query.getResultList();
	}

	public static void add(Apartment object) {
		Transaction sa = session.beginTransaction();

		try {
			session.save(object);
			sa.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			sa.rollback();
			e.printStackTrace();
		}

	}

	public static void delete(Apartment object) {
		Transaction sa = session.beginTransaction();

		try {
			session.delete(object);
			sa.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			sa.rollback();
			e.printStackTrace();
		}

	}

	public static void update(Apartment object) {
		Transaction sa = session.beginTransaction();

		try {
			session.update(object);
			sa.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			sa.rollback();
			e.printStackTrace();
		}
	}

}
